package com.yhjapp.onethingoneyard.onethingoneyard;

import android.app.Activity;
import android.app.Application;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.StrictMode;
import android.support.v4.util.LruCache;
import android.util.Log;

//import com.huifaapp.mall.afinal.Constants;
//import com.huifaapp.mall.uitils.AppManager;
//import com.kepler.jd.Listener.AsyncInitListener;
//import com.kepler.jd.login.KeplerApiManager;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.umeng.socialize.Config;
import com.umeng.socialize.PlatformConfig;
import com.umeng.socialize.UMShareAPI;

import java.io.ByteArrayOutputStream;

import cn.jpush.android.api.JPushInterface;


public class APP extends Application {

    public static boolean isDebug = BuildConfig.DEBUG;
    private static APP mAPP = null;
    public LruCache<String, Bitmap> map;


    // 需要改成给您的 appKey 还有keySecret
    // 京东开普勒
    public static final String appKey = "2d67b6f7d09e42c28d49fa88248db03c";
    public static final String keySecret = "4fb7e608d6c743b5a4dd05cffc8941d3";
    public static APP getInstance() {

        return mAPP;
    }
    @Override
    public void onCreate() {
        super.onCreate();
        /**
         * 申请手机的1/8内存
         */
        int cacheSize = (int) Runtime.getRuntime().maxMemory() / 8;
        map = new LruCache<String, Bitmap>(cacheSize) {
            @Override
            protected int sizeOf(String key, Bitmap value) {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                //不压缩图片
                value.compress(Bitmap.CompressFormat.JPEG, 100, baos);
                int size = baos.size();
                baos = null;
                return size;
            }
        };
//
//        KeplerApiManager.asyncInitSdk(this, appKey, keySecret,
//                new AsyncInitListener() {
//                    @Override
//                    public void onSuccess() {
//                        Log.e("Kepler", "Kepler asyncInitSdk onSuccess ");
//                    }
//                    @Override
//                    public void onFailure() {
//
//                        Log.e("Kepler",
//                                "Kepler asyncInitSdk 授权失败，请检查lib 工程资源引用；包名,签名证书是否和注册一致");
//
//                    }
//                });


        StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
        StrictMode.setVmPolicy(builder.build());
//        builder.detectFileUriExposure();

        JPushInterface.setDebugMode(isDebug); // 设置开启日志,发布时请关闭日志
        JPushInterface.init(this); // 初始化 JPush

        //创建默认的ImageLoader配置参数
        ImageLoaderConfiguration configuration = ImageLoaderConfiguration
                .createDefault(this);
        ImageLoader.getInstance().init(configuration);

        Utils.init(this);
        mAPP = this;
        Config.DEBUG = true;
        UMShareAPI.get(this);
//        // 微信 appid appsecret
//        PlatformConfig.setWeixin(Constants.WX_APPID, Constants.WX_APP_SECRET);
//        // 新浪微博 appkey appsecret
//        PlatformConfig.setSinaWeibo("2396589217", "8bef67db99199d7c720704c19d55301e","");
//        // QQ和Qzone appid appkey
//        PlatformConfig.setQQZone("1106165153", "yLcSrhCQw1TkWtUo");
        //程序里所有的activity生命周期方法都会走这个回调(包括第三方activity)
        registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
            @Override
            public void onActivityCreated(Activity activity, Bundle bundle) {
                //把activity加入到栈
//                AppManager.getAppManager().addActivity(activity);
            }

            @Override
            public void onActivityStarted(Activity activity) {

            }

            @Override
            public void onActivityResumed(Activity activity) {

            }

            @Override
            public void onActivityPaused(Activity activity) {

            }

            @Override
            public void onActivityStopped(Activity activity) {

            }

            @Override
            public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {

            }

            @Override
            public void onActivityDestroyed(Activity activity) {

            }
        });

    }
}

//package com.huifaapp.mall;
//
//import android.app.Activity;
//import android.app.Application;
//import android.os.Bundle;
//import android.os.StrictMode;
//
//import com.blankj.utilcode.BuildConfig;
//import com.blankj.utilcode.util.Utils;
//import com.huifaapp.mall.afinal.Constants;
//import com.huifaapp.mall.uitils.AppManager;
//import com.nostra13.universalimageloader.core.ImageLoader;
//import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
//import com.umeng.socialize.Config;
//import com.umeng.socialize.PlatformConfig;
//import com.umeng.socialize.UMShareAPI;
//
//import cn.jpush.android.api.JPushInterface;
//
//
//public class APP extends Application {
//
//    public static boolean isDebug = BuildConfig.DEBUG;
//    private static APP mAPP = null;
//    public static APP getInstance() {
//
//        return mAPP;
//    }
//    @Override
//    public void onCreate() {
//        super.onCreate();
//
//        StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
//        StrictMode.setVmPolicy(builder.build());
//        builder.detectFileUriExposure();
//
//        JPushInterface.setDebugMode(isDebug); // 设置开启日志,发布时请关闭日志
//        JPushInterface.init(this); // 初始化 JPush
//
//        //创建默认的ImageLoader配置参数
//        ImageLoaderConfiguration configuration = ImageLoaderConfiguration
//                .createDefault(this);
//        ImageLoader.getInstance().init(configuration);
//
//        Utils.init(this);
//        mAPP = this;
//        Config.DEBUG = true;
//        UMShareAPI.get(this);
//        // 微信 appid appsecret
//        PlatformConfig.setWeixin(Constants.WX_APPID, Constants.WX_APP_SECRET);
//        // 新浪微博 appkey appsecret
//        PlatformConfig.setSinaWeibo("2396589217", "8bef67db99199d7c720704c19d55301e","");
//        // QQ和Qzone appid appkey
//        PlatformConfig.setQQZone("1106165153", "yLcSrhCQw1TkWtUo");
//        //程序里所有的activity生命周期方法都会走这个回调(包括第三方activity)
//        registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
//            @Override
//            public void onActivityCreated(Activity activity, Bundle bundle) {
//                //把activity加入到栈
//                AppManager.getAppManager().addActivity(activity);
//            }
//
//            @Override
//            public void onActivityStarted(Activity activity) {
//
//            }
//
//            @Override
//            public void onActivityResumed(Activity activity) {
//
//            }
//
//            @Override
//            public void onActivityPaused(Activity activity) {
//
//            }
//
//            @Override
//            public void onActivityStopped(Activity activity) {
//
//            }
//
//            @Override
//            public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
//
//            }
//
//            @Override
//            public void onActivityDestroyed(Activity activity) {
//
//            }
//        });
//
//    }
//}
